<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
?>

<?php

    $page_current['title'] 				= isset($page_current['title']) ? $page_current['title'] : "";
    $page_current['page_title'] 		= isset($page_current['page_title']) ? $page_current['page_title'] : "";
    $page_current['meta_keywords'] 		= isset($page_current['meta_keywords']) ? $page_current['meta_keywords'] : "";
    $page_current['meta_description'] 	= isset($page_current['meta_description']) ? $page_current['meta_description'] : "";
    $page_current['content'] 			= isset($page_current['content']) ? $page_current['content'] : "";
	$page_current['hook'] 				= isset($page_current['hook']) ? $page_current['hook'] : "";
	$page_current['rendertype'] 			= isset($page_current['rendertype']) ? $page_current['rendertype'] : "";
	$page_current['contenttype'] 			= isset($page_current['contenttype']) ? $page_current['contenttype'] : "";

?>

<?php echo App::Helper("Javascript")->validation_map(array('_errBg'=>ERROR_BACKGROUND,'_dflBg'=>"#CECECE",'_autoSubmit'=>'true','_errorMark'=>'inline','_errToolTips'=>'false')); ;?>

<?php

	if( $action == 'create' || $action == 'createsnip')
	{
        echo $this->get_tag("form",array("action"=>$this->baseurl("/page/manage/{$action}"),"class"=>"app_form app_validation","method"=>"post"));
	}
    else
	{
        echo $this->get_tag("form",array("action"=>$this->baseurl("/page/manage/{$action}/{$page_id}"),"class"=>"app_form","id"=>"auto_chk_submit","method"=>"post"));
	}

	App::Helper('Toolbar')->setTitle("Static page manager")->setBtnSave()->setBtnDelete()->setBtnfileManager();
    if(isset($page_id) && isset($static_page_arr[$page_id]))
	{
		App::Helper('Toolbar')->setBtnCustomHtml(App::Helper("Html")->ButtonTag("Button[View][Page]","View Page",array("onclick"=>"document.location='" . $this->baseurl("/page/view/{$static_page_arr[$page_id]}") . "';")));
	}
    App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'static_page_save_top',"page"=>$page_current));

?>
<input type="hidden" name="data[Page][contenttype]" value="<?php
if($action == 'create') echo appRain_Base_Modules_PageManager::CONTENT;
elseif($action == 'createsnip') echo appRain_Base_Modules_PageManager::SNIP;
else echo $page_current['contenttype'] ;
?>" />
<?php
	$Html = App::load("Helper/Html");
	$Grid = App::Module('DataGrid')->setDisplay('FormListing');
	if( $action == 'create' || $action == 'createsnip')
	{
		$Grid->addRow("Name",$Html->inputTag('data[Page][name]', "",array("class" => "app_input check_notempty","id" => "page_name")));
	}
	else
	{
		if($page_current['contenttype'] == 'Snip')
		{
			$Grid->addRow("Select Page",$Html->selectTag('data[Page][id]', $static_page_arr,$page_id,array("id" => "page_id","style"=>"width:200px")))
				 ->addRow("&nbsp;","{{name=UI type=staticpage name={$page_current['name']}}} <a href=\"#\" title=\"Copy this code in other page to execute PHP Commnad\">What is this?</a> <a href=\"#\" id=\"dialog-modal-open\">View All Codes</a>");
		}
		else
		{
			$Grid->addRow("Select Page",$Html->selectTag('data[Page][id]', $static_page_arr,$page_id,array("id" => "page_id","style"=>"width:200px")) . "<div style=\"float:right\"> " . App::Module('AdminpanelUI')->getPagemanagerHookList($this->theme,$page_current) . " </div>")
			     ->addRow("&nbsp;","{{name=UI type=staticpage name={$page_current['name']} autoformat=off}} <a href=\"#\" title=\"Copy this code in other page to replace the content\">What is this?</a> <a href=\"#\" id=\"dialog-modal-open\">View All Codes</a>");
		}
	}

	if( $this->get_config('disable_page_meta_options') != "Yes" && $page_current['contenttype'] != 'Snip' && $action != 'createsnip')
	{
		$Grid->addRow("Page Meta Title",$Html->textareaTag('data[Page][page_title]', $page_current['page_title'],array("class" => "app_input","id" => "page_title")))
			 ->addRow("Meta Keywords",$Html->textareaTag('data[Page][meta_keywords]', $page_current['meta_keywords'],array("class" => "app_input","id" => "meta_keywords")))
			 ->addRow("Meta Descriptions",$Html->textareaTag('data[Page][meta_description]', $page_current['meta_description'],array("style"=>"overflow:none","class" => "app_input","id" => "meta_description")));
	}


	if($page_current['contenttype'] == 'Snip' || $action == 'createsnip')
	{
		if(trim($page_current['content'])=="")
		{
			$page_current['content'] =
'<?php
/**
* Write PHP Code
*
* Example:
* $Config = App::Config()->siteInfo();
* pre($Config);
*/
?>';
		}
		$Grid->addRow("Content",$Html->textareaTag('data[Page][content]', $page_current['content'],array("rows" => "22","class" => "app_input","id" => "page_content")));
	}
	else
	{
		$Grid->addRow("Title",$Html->inputTag('data[Page][title]', $page_current['title'],array("class" => "app_input","id" => "title")));
		$Grid->addRow("Content",$Html->textareaTag('data[Page][content]', $page_current['content'],array("rows" => "32","class" => "app_input richtexteditor","id" => "page_content")));
	}

	$Grid->render();

	echo App::Module('AdminPanelUi')->pageCodesList('Html');
/*Call the tools bar*/
App::Helper('Toolbar')->setBtnSave()->setBtnBack()->setFormJustified(true)->Render(array('code'=>'static_page_save_bottom',"page"=>$page_current));
echo $this->get_tag("/form");
if( $action != 'create'):
echo "<script type=\"text/javascript\">
   jQuery(document).ready(function ()
   {
        jQuery('#page_id').change(function(){
            if( this.value != '')
            {
                window.location = siteInfo.baseUrl + '/page/manage/update/' + this.value;
            }
        });
    });
</script>";
endif;
